package cn.hy.http;

import cn.hy.vo.UserVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

public class RestTemplateCall {

    public void callGet() {
        // http://USER-SERVICE/user?name={name)
        RestTemplate restTemplate = new RestTemplate();
        Map<String, String> params = new HashMap<>();
        params.put("name", "dada");  //
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://USER-SERVICE/user?name={name}", String.class, params);
        //restTemplate.exchange()
    }

    public void callPost() {
        RestTemplate restTemplate = new RestTemplate();
        UserVo userVo = UserVo.builder().age(18).name("hy").build();
        ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://USER-SERVICE/user", userVo, String.class);
        String body = responseEntity.getBody();

    }
}
